package com.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crm.common.result.AjaxResult;
import com.crm.common.utils.StringUtils;
import com.crm.domain.DictData;
import com.crm.dto.DictDataPageQueryDto;
import com.crm.mapper.DictDataMapper;
import com.crm.service.DictDataService;
import org.springframework.stereotype.Service;

@Service
public class DictDataServiceImpl extends ServiceImpl<DictDataMapper,DictData> implements DictDataService {
    @Override
    public AjaxResult pageDictData(DictDataPageQueryDto dto) {
        AjaxResult ajaxResult = new AjaxResult();
        Page<DictData> dictDataPage = new Page<>();
        LambdaQueryWrapper<DictData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(dto.getDictType()), DictData::getDictType, dto.getDictType());
        wrapper.eq(StringUtils.isNotEmpty(dto.getDictLabel()), DictData::getDictLabel, dto.getDictLabel());
        wrapper.eq(dto.getDictStatus()!=null,DictData::getStatus,dto.getDictStatus());
        Page<DictData> page = super.page(dictDataPage, wrapper);
        ajaxResult.put("total", page.getTotal());
        ajaxResult.put("rows", page.getRecords());
        return ajaxResult;
    }
}
